<?php

header("Content-type: text/html; charset=utf-8");
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class htmFileverify {
    /* 先判断判断上传type类型 */

    function verifyName($htm_file) {
        if ($htm_file["name"] == '') {
            exit("文件名不合法，请更改文件名后再<a href='index.php'>重新上传</a>！");
        } else {
            $this->verifyError($htm_file);
        }
    }

    function verifyError($htm_file) {
        if ($htm_file["error"] > 0) {
            switch ($htm_file["error"]) {
                case 1:
                    exit("上传的文件超过了服务器的限制，请精简一下！");
                    break;
                case 2:
                    exit("超过了浏览器的上传限制！");
                    break;
                case 3:
                    exit("文件没有上传完整！");
                    break;
                case 4:
                    exit("没有找到要上传的文件！");
                    break;
                case 5:
                    exit("文件丢失请重新上传！");
                    break;
                case 6:
                    exit("文件写入权限失败，请重新上传！");
                    break;
            }
        } else {
            $this->verifyType($htm_file);
        }
    }

    function verifyType($htm_file) {
        if ($htm_file["type"] != "text/html") {
            exit("上传的文件不是html！请重新上传！");
        } else {
            $this->verifyMemory($htm_file);
        }
    }

    function verifyMemory($htm_file) {
        $file_tmp_name = $htm_file["tmp_name"];
        $GLOBALS["htm_path"] = getcwd() . "/htm_file/" . $htm_file["name"];
        if ($htm_file["error"] == 0) {
            move_uploaded_file($file_tmp_name, $GLOBALS["htm_path"]);
        } else {
            exit("文件移动失败！");
        }
    }

}

$upload_htm = new htmFileverify();
$upload_htm->verifyName($_FILES["upload_htm_file"]);

$new_htm_file = basename($GLOBALS["htm_path"]);